package com.treegrid;

import java.io.InputStream;
import java.util.Iterator;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

public class JsonReader {

	public static void main(String[] args) {
		InputStream is = JsonReader.class.getResourceAsStream("data-original.txt");
		JSONTokener tokener = new JSONTokener(is);
		JSONArray array = new JSONArray(tokener);
		
		int length = array.length();
		for (int i = 0; i < length; i++) {
			JSONObject o = array.getJSONObject(i);
			Iterator it = o.keys();
			while (it.hasNext()) {
				String key = (String) it.next();
				//System.out.println(key + "-----------" + o.getString(key));
				if (isNumeric(key)) {
					o.remove(key);
					it = o.keys();
				}
			}
			System.out.println(o.toString());
		}
	}

	private static boolean isNumeric(String key) {
		Pattern pattern = Pattern.compile("[0-9]*"); 
	    return pattern.matcher(key).matches();    
	}

}
